package com.zixuan.sina.controller;

import com.zixuan.sina.entity.MessageLog;
import com.zixuan.sina.entity.UserRelactionShip;
import com.zixuan.sina.entity.vo.FriendVo;
import com.zixuan.sina.entity.vo.UserFriend;
import com.zixuan.sina.entity.vo.UserRelactionShipVo;
import com.zixuan.sina.service.UserReflectionShipService;
import com.zixuan.sina.utils.Result;
import org.apache.ibatis.executor.loader.ResultLoader;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/reflection/")
public class UserReflectionShipController {
    @Resource
    private UserReflectionShipService userReflectionShipService;

    /**
     * 根据userId查询好友申请信息
     */
    @GetMapping("list/{userId}")
    public Result listReflectShip(@PathVariable("userId") String userId, @RequestParam("start") long start,@RequestParam("end") long end){
            return userReflectionShipService.listReflectShip(userId,start,end);
    }
    /**
     * 添加好友
     */
    @PostMapping("addFriend")
    public Result addFriend(@RequestBody UserRelactionShip userRelactionShip){
        return  userReflectionShipService.addFriend(userRelactionShip);
    }
    //同意好友请求
    @PostMapping("applicationReflection")
    public Result applicationReflection(@RequestBody UserRelactionShip userRelactionShip){
        return userReflectionShipService.applicationReflection(userRelactionShip);
    }
    /**
     *好友列表
     */
    @GetMapping("listFriendList/{userId}")
    public Result listFriendList(@PathVariable("userId") String userId, @RequestParam("start") long start,@RequestParam("end") long end){
        return userReflectionShipService.listFriendList(userId,start,end);
    }
    //根据接收者id查询指定好友信息
    @GetMapping("findFriendInfoById")
    public Result findFriendInfoById(@RequestParam("userId") String userId,@RequestParam("friendId") String friendId){
        return userReflectionShipService.findFriendInfoById(userId,friendId);
    }
    //查询当前用户好友申请列表(别人给我发的)

    /**
     *
     * @param userId
     * @param identify 1别人给我发的  0 我发给别人的
     * @return
     */
    @GetMapping("getApplicationListByUserId/{start}/{end}")
    public Result getApplicationListByUserId(@RequestParam("userId") String userId,@RequestParam("identify") int identify,@PathVariable("start") int start,@PathVariable("end") int end){
        return userReflectionShipService.getApplicationListByUserId(userId,identify,start,end);
    }
    //获得新增好友申请条数
    @GetMapping("getApplicationCount")
    public Result getApplicationCount(@RequestParam("userId") String userId){
        return userReflectionShipService.getApplicationCount(userId);
    }
    //处理好友申请
    @PostMapping("handleApplication")
    public Result handleApplication(@RequestBody UserRelactionShipVo userRelactionShipVo){
        return userReflectionShipService.handleApplication(userRelactionShipVo);
    }
    //查询当前用户和目标用户是否是好友关系
    @GetMapping("isFriendRelation")
    public Result isFriendRelation(@RequestParam("userId") String userId,@RequestParam("friendId") String friendId){
        return userReflectionShipService.isFriendRelation(userId,friendId);
    }


    /**
     * 查询当前用户好友列表
     */
    @GetMapping("getFriendByUserId")
    public Result getFriendByUserId(){
     List<UserFriend> userFriendList=   userReflectionShipService.getFriendByUserId();
        return Result.ok(userFriendList);
    }
    /**
     * 查询当前用户与好友的聊天记录
     */
    @GetMapping("getFriendMessage")
    public Result getFriendMessage(@RequestParam("friendId") Long friendId){
        List<MessageLog> messageLogs=userReflectionShipService.getFriendMessage(friendId);
        return Result.ok(messageLogs);
    }
    /**
     * 查询所有用户 展示到好友列表中去
     */
    @GetMapping("listFriend")
    public Result listFriend(@RequestParam(value = "key",required = false) String key){
       List<FriendVo> friendVos= userReflectionShipService.listFriend(key);
        return Result.ok(friendVos);
    }
}
